#e
#Title[zNuт̈ȁv]
#Text[X^[n^[Btt|c]
#ScriptVersion[2]
script_enemy_main
{
	let scroll=0;
	let flag=0;
	let cx=GetCenterX();//STGV[̒SxW擾
	let cy=GetCenterY();//STGV[̒SyW擾
	let boss=GetCurrentScriptDirectory~"img\boss7-2.png";
	let eye=GetCurrentScriptDirectory~"img\bg7-1.png";
	let asa=GetCurrentScriptDirectory~"img\bg7-2.png";
	LoadUserShotData(GetCurrentScriptDirectory~"shot.txt");
	@Initialize
	{
		SetScore(30000);
		SetLife(300);
		SetDamageRate(10,0);
		SetMovePosition02(cx,cy-120,60);
		SetTimer(80);
		SetInvincibility(60);
		LoadGraphic(boss);
		LoadGraphic(eye);
		LoadGraphic(asa);
		shottask;
		movetask;
		movetask2;
		drawtask;
		bombtask;
		CutIn(YOUMU,"zNuт̈ȁv",0,0,0,0,0);//XyJ[h\
	}
	@MainLoop
	{
		yield;
	}
	@Finalize
	{
		loop(16)
		{
			CreateItem(ITEM_SCORE,GetX+rand(-30,30),GetY+rand(-30,30));
		}
		CreateItem(ITEM_BOMB,GetX,GetY);
		DeleteGraphic(boss);
		DeleteGraphic(eye);
		DeleteGraphic(asa);
	}
	@DrawLoop
	{
		SetTexture(boss);	
		if(flag==1)
		{
			SetGraphicRect(52,0,81,63);
		}
		else if(flag==2)
		{
			SetGraphicRect(24,0,52,63);
		}
		else
		{
			SetGraphicRect(0,0,24,63);
		}
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,0);
		DrawGraphic(GetX,GetY);
	}
	@BackGround
	{
		SetColor(128,128,128);
		SetTexture(eye);	
		SetGraphicRect(0,0,384,448);
		SetAlpha(255);
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,0);
		DrawGraphic(cx,cy);
		SetColor(255,255,255);
		SetTexture(asa);	
		SetGraphicRect(0,0,888,189*5);
		SetAlpha(64);
		SetGraphicScale(0.5,0.75);
		SetGraphicAngle(0,0,0);
		DrawGraphic(cx+scroll,cy);
		DrawGraphic(cx+scroll-444,cy);
		if(scroll>444)
		{
			scroll=0;
		}
	}
	task shottask
	{
		let angle=0;
		wait(120);
		loop
		{
			loop(3)
			{
				if (GetLife>150)
				{
					electoro(GetX,GetY,GetAngleToPlayer+rand(-30,30),0,0);
				}
				else
				{
					electoro(GetX,GetY,GetAngleToPlayer+rand(0,40),0,0);
					electoro(GetX,GetY,GetAngleToPlayer+rand(-40,0),0,0);
				}
				wait(120);
				loop(6)
				{
					angle=rand(0,360);
					loop(10)
					{
						CreateShot01(GetX,GetY,3,angle,155,0);
					angle+=36;
					}
					wait(5);
				}
			wait(90);
			}
			wait(60);
			loop(40)
			{
				CreateShot01(GetX,GetY,5,90+rand(-5,5),137,0);
				wait(3);
			}
			wait(150);
		}
	}
	task movetask
	{
		wait(120);
		loop
		{
			loop(3)
			{
				wait(120);
				SetMovePosition02(GetX+240*cos(GetAngleToPlayer),GetY+240*sin(GetAngleToPlayer),30);
				wait(120);
			}
			wait(30);
			SetMovePosition02(GetPlayerX,16,30);
			wait(180);
			SetMovePosition02(GetX+240*cos(GetAngleToPlayer),GetY+240*sin(GetAngleToPlayer),60);
			wait(120);
		}
	}
	task movetask2
	{
		wait(120);
		loop
		{
			if(GetX<GetClipMinX){SetX(GetClipMinX)}
			if(GetX>GetClipMaxX){SetX(GetClipMaxX)}
			if(GetY<GetClipMinY){SetY(GetClipMinY)}
			if(GetY>GetClipMaxY){SetY(GetClipMaxY)}
			yield;
		}
	}
	task drawtask
	{
		let x=0;
		loop
		{	
			if(GetX>x+0.5)
			{
				flag=1;
			}
			else if(GetX<x-0.5)
			{
				flag=2;
			}
			else
			{
				flag=0;
			}
			x=GetX;
			scroll++;
			yield;
		}
	}
	task bombtask
	{
		loop
		{
			if(OnBomb)
			{
				SetAlpha(64);
				SetDamageRate(0,0);
			}
			else
			{
				SetAlpha(255);
				SetDamageRate(10,0);
				SetCollisionA(GetX(),GetY(),24);
				SetCollisionB(GetX(),GetY(),24);
			}
			yield;
		}
	}
	task electoro(let x, let y, let angle,let angle2,let flag)
	{
		let length=rand(20,30);
		let width=0;
		let count=0;
		let obj = Obj_Create(OBJ_LASER);
		Obj_SetPosition(obj, x, y);
		Obj_SetAngle(obj, angle+angle2);
		ObjShot_SetGraphic(obj, 254);
		ObjShot_SetDelay(obj, 0);
		ObjLaser_SetLength(obj, length);
		ObjLaser_SetWidth(obj, 4);
		Obj_SetAutoDelete(obj,false);
		ObjLaser_SetSource(obj, false);
		Obj_SetCollisionToPlayer(obj,false);
		yield;
		if(Obj_GetY(obj)<GetClipMaxY+16&&Obj_GetY(obj)>GetClipMinY-16&&Obj_GetX(obj)<GetClipMaxX+16&&Obj_GetX(obj)>GetClipMinX-16)
		{
				if(GetEnemyShotCount<600||flag<10)
				{
					if(GetEnemyShotCount<240||flag<30)
					{
						electoro(Obj_GetX(obj)+(length-5)*cos(angle+angle2),Obj_GetY(obj)+(length-5)*sin(angle+angle2),GetAngleToPlayer+rand(-30,30),angle2,flag+1);
					}
					if(GetEnemyShotCount<240&&flag%10==5)
					{
						electoro(Obj_GetX(obj)+(length-5)*cos(angle+angle2),Obj_GetY(obj)+(length-5)*sin(angle+angle2),GetAngleToPlayer+rand(-30,30),rand(20,40),flag+1);
					}
					if(GetEnemyShotCount<240&&flag%10==0)
					{
						electoro(Obj_GetX(obj)+(length-5)*cos(angle+angle2),Obj_GetY(obj)+(length-5)*sin(angle+angle2),GetAngleToPlayer+rand(-30,30),rand(-20,-40),flag+1);
					}
					if(flag<=15)
					{
						electoro2(Obj_GetX(obj)+length*cos(angle+angle2),Obj_GetY(obj)+length*sin(angle+angle2),GetAngleToPlayer+rand(-30,30),rand(-30,30),flag+1);
					}
				}
		}
		wait(5);
		ObjLaser_SetWidth(obj, width);
		while(!Obj_BeDeleted(obj))
		{
			if(count==100)
			{
				Obj_Delete(obj);
			}
			if(count<60&&count>30)
			{
				width+=0.3;
				Obj_SetCollisionToPlayer(obj,false);
			}
			else if(count>70)
			{
				width-=0.3;
				Obj_SetCollisionToPlayer(obj,false);
			}
			else if(count<60)
			{
				Obj_SetCollisionToPlayer(obj,false);
			}
			else
			{
				Obj_SetCollisionToPlayer(obj,true);
			}
			ObjLaser_SetLength(obj, length);
			ObjLaser_SetWidth(obj, width);
			count++;
			yield;
		}
	}
	task electoro2(let x, let y, let angle,let angle2,let del)
	{
		let length=rand(0,30);
		let flag=rand_int(0,30);
		let width=0;
		let count=0;
		let obj = Obj_Create(OBJ_LASER);
		Obj_SetPosition(obj, x, y);
		Obj_SetAngle(obj, angle+angle2);
		ObjShot_SetGraphic(obj, 254);
		ObjShot_SetDelay(obj, 0);
		ObjLaser_SetLength(obj, length);
		ObjLaser_SetWidth(obj, 4);
		Obj_SetAutoDelete(obj,false);
		ObjLaser_SetSource(obj, false);
		Obj_SetCollisionToPlayer(obj,false);
		wait(6);
		ObjLaser_SetWidth(obj, width);
		while(!Obj_BeDeleted(obj))
		{
			if(count==100)
			{
				Obj_Delete(obj);
			}
			if(count<60&&count>30)
			{
				width+=0.2;
				Obj_SetCollisionToPlayer(obj,false);
			}
			else if(count>70)
			{
				width-=0.2;
				Obj_SetCollisionToPlayer(obj,false);
			}
			else if(count<60)
			{
				Obj_SetCollisionToPlayer(obj,false);
			}
			else
			{
				Obj_SetCollisionToPlayer(obj,true);
			}
			ObjLaser_SetLength(obj, length);
			ObjLaser_SetWidth(obj, width);
			count++;
			yield;
		}
	}
	function wait(w) 
	{
		loop(w)
		{
			yield;
		}
	}
}